package com.aurora.calculator.ui

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.aurora.calculator.data.symbols
import com.aurora.calculator.ui.theme.CalculatorTheme

/**
 * 单个键盘按钮组件
 */
@Composable
fun CalculatorButton(
    modifier: Modifier = Modifier,
    symbol: String = "N",
    onClick: () -> Unit
) {
    Box(
        modifier = Modifier
            .clip(CircleShape)
            .clickable { onClick() }
            .then(modifier),
        contentAlignment = Alignment.Center
    ) {
        Text(
            text = symbol,
            fontSize = 30.sp,
            color = when (symbol) {
                symbols[0][0] -> CalculatorTheme.colors.AcTextColor
                symbols[4][3] -> CalculatorTheme.colors.EqualTextColor
                else -> CalculatorTheme.colors.ButtonTextColor
            }
        )
    }
}

@Composable
@Preview
fun CalculatorButtonPreV() {
    CalculatorButton(modifier = Modifier.size(50.dp, 50.dp).background(Color.Gray)) {}
}